package cn.kongwg.demo03;

import java.util.concurrent.TimeUnit;

/**
 * @author kongwg
 * @create 2021-05-27 16:16
 */
public class DieLockDemo {
    private static Object object1 = new Object();
    private static Object object2 = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (object1) {
                System.out.println();
                 try {
                     TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {e.printStackTrace();}
                synchronized (object2) {
                    System.out.println();
                }
            }
        }, "a").start();

        new Thread(() -> {
            synchronized (object2) {
                System.out.println();
                 try {TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {e.printStackTrace();}
                synchronized (object1) {
                    System.out.println();
                }
            }
        }, "b").start();
    }
}
